package com.lfc.dp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test2 {
    public static void main(String[] args) {
//        int nums[] = {3, 4, 6, 8};
//        System.out.println(maxScore(nums));
    }

    //    public static boolean isCircularSentence(String sentence) {
//        String[] s = sentence.split(" ");
//        if (s[0].charAt(0)!=s[s.length-1].charAt(s[s.length-1].length()-1)) return false;
//        for (int i = 0; i < s.length - 1; i++) {
//            if (s[i].charAt(s[i].length()-1)!=s[i+1].charAt(0)) return false;
//        }
//        return true;
//    }
    public static long dividePlayers(int[] skill) {
        Arrays.sort(skill);
        int n = skill.length - 1, i = 1, j = n - 1;
        long ans = skill[0] * skill[n], avg = skill[0] + skill[n];
        while (i < j) {
            if (skill[i] + skill[j] != avg) return -1;
            ans += skill[i] * skill[j];
            i++;
            j--;
        }
        return ans;

    }

    public static int maxScore(int[] nums) {
        int m = nums.length, max = 1 << m;
        int ans[] = new int[max];
        for (int i = 1; i < max; i++) {
            int k = Integer.bitCount(i);
            if (k % 2 == 0) {
                List<Integer> bits = new ArrayList<>();
                for (int j = 0; j < m; j++) {
                    if ((i & (1 << j)) != 0) {
                        bits.add(j);
                    }
                }
                for (int l1 = 0; l1 < bits.size(); l1++) {
                    for (int l2 = l1 + 1; l2 < bits.size(); l2++) {
                        int a = bits.get(l1), b = bits.get(l2);
                        ans[i] = Math.max(ans[i], ans[i ^ (1 << a) ^ (1 << b)] + gcd(nums[a], nums[b]) * k / 2);
                    }
                }
            }
        }
        return ans[max - 1];
    }

    public static boolean areNumbersAscending(String s) {
        int cur = 0;
        String[] s1 = s.split(" ");
        for (int i = 0; i < s1.length; i++) {
            String s2 = s1[i];
            try {
                Integer j = Integer.valueOf(s2);
                if (j <= cur) {
                    return false;
                }
                cur = j;

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return true;
    }

    static int gcd(int a, int b) {
        return a < b ? gcd(b, a) : a % b == 0 ? b : gcd(b, a % b);
    }
}
